package zhao.tx.eecs;

import android.content.Context;
import android.os.Build.VERSION;
import android.util.Log;

import com.andware.volley.Request;
import com.andware.volley.RequestQueue;
import com.andware.volley.Response;
import com.andware.volley.toolbox.HttpClientStack;
import com.andware.volley.toolbox.HttpStack;
import com.andware.volley.toolbox.HurlCookieStack;
import com.andware.volley.toolbox.HurlStack;
import com.andware.volley.toolbox.Volley;

import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;

import java.net.HttpCookie;
import java.util.List;


/**
 * Created by ishishuji on 14-7-10.
 */
public class MyVolley {

    private static RequestQueue mRequestQueue;

    private static CookieStore cookieStore;

    private static HurlCookieStack httpStack;


    public MyVolley () {

    }

    protected static void init ( Context context ) {

        if ( VERSION.SDK_INT >= 9 ) {
            Log.i ( "Cookie", "init>=9" );
            httpStack = new HurlCookieStack ();
            mRequestQueue = Volley.newRequestQueue ( context, httpStack );

        } else {

            Log.i ( "Cookie", "init<9" );
            DefaultHttpClient httpclient = new DefaultHttpClient ();

            HttpStack myHttpStack = new HttpClientStack ( httpclient );
            mRequestQueue = Volley.newRequestQueue ( context, myHttpStack );


        }

    }

    public static Cookie getCookie () {
        return cookieStore.getCookies ().get ( 0 );
    }

    public static RequestQueue getRequestQueue () {
        if ( mRequestQueue != null ) {
            return mRequestQueue;
        } else {
            throw new IllegalStateException ( "RequestQueue not initialized" );
        }
    }


}
